package com.wjh.mirna.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wjh.mirna.dao.CscoreDao;
import com.wjh.mirna.dao.DiseasesDao;
import com.wjh.mirna.dao.LscoreDao;
import com.wjh.mirna.dao.ScoreDao;
import com.wjh.mirna.model.Diseases;
import com.wjh.mirna.service.DiseasesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class DiseasesServiceImpl implements DiseasesService {
    @Autowired
    DiseasesDao diseasesDao;
    @Autowired
    ScoreDao scoreDao;
    @Autowired
    LscoreDao lscoreDao;
    @Autowired
    CscoreDao cscoreDao;
    @Override
    public Page selectDnameAndScoreByPage(Page page, Diseases disease) {
        List<String> dnameList = diseasesDao.selectDnameByPage(page, disease);
        List<List> data = new ArrayList<>();
        List<Double> score = new ArrayList<>();
        List<Double> score1 = new ArrayList<>();
        List<Double> score2 = new ArrayList<>();
        dnameList.stream().forEach(dname ->{
            List<Double> scores = scoreDao.selectByDname(dname);

            if(scores.size() > 0){
                score.add(scores.get(0));
            }else {
                score.add(0.0);
            }
        });
        dnameList.stream().forEach(dname ->{
            List<Double> scores = lscoreDao.selectByDname(dname);
            if(scores.size() > 0){
                score1.add(scores.get(0));
            }else {
                score1.add(0.0);
            }
        });
        dnameList.stream().forEach(dname ->{
            List<Double> scores = cscoreDao.selectByDname(dname);
            if(scores.size() > 0){
                score2.add(scores.get(0));
            }else {
                score2.add(0.0);
            }
        });
     data.add(dnameList);
     data.add(score);
     data.add(score1);
     data.add(score2);
     page.setRecords(data);
        System.out.println(page.getRecords());
     return page;
    }

}
